var express = require("express");
var router = express.Router();
const categoryModel = require("../../models/categoryModel");

// 获取一级分类列表
router.get("/categoryList", (req, res) => {
    categoryModel.find()
    .then(data => {
        if (data.length === 0) {
            return res.json({
              code: 200,
              msg: "数据为空",
              data: data,
            });
          }
          return res.json({
            code: 200,
            msg: "获取一级分类列表成功",
            data: data,
          });
    })
    .catch((err) => {
        return res.json({
          code: "1001",
          msg: "数据库读取失败~~~",
          data: null,
        });
      });
})

module.exports = router